package com.zcxx.cotton.base;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zcxx.cotton.base.domain.MembraneChip;
import com.zcxx.cotton.base.service.IMembraneChipService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 芯片膜Controller
 * @author ruoyi
 * @date 2025-09-18
 */
@RestController
@RequestMapping("/membrane/chip")
public class MembraneChipController extends BaseController
{
    @Autowired
    private IMembraneChipService membraneChipService;

    /**
     * 查询芯片膜列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MembraneChip membraneChip) {
        startPage();
        List<MembraneChip> list = membraneChipService.selectMembraneChipList(membraneChip);
        return getDataTable(list);
    }


    /**
     * 导出芯片膜列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, MembraneChip membraneChip) {
        List<MembraneChip> list = membraneChipService.selectMembraneChipList(membraneChip);
        ExcelUtil<MembraneChip> util = new ExcelUtil<MembraneChip>(MembraneChip.class);
        util.exportExcel(response, list, "芯片膜数据");
    }

    /**
     * 获取芯片膜详细信息
     */
    @GetMapping(value = "/{chipId}")
    public AjaxResult getInfo(@PathVariable("chipId") Long chipId) {
        return success(membraneChipService.getById(chipId));
    }

    /**
     * 新增或者修改芯片膜
     */
    @PostMapping("/addUpdateMembraneChip")
    public AjaxResult add(@RequestBody MembraneChip membraneChip) {
        if(membraneChip.getChipId()==null){ //新增
            return toAjax(membraneChipService.save(membraneChip));
        }
        return toAjax(membraneChipService.updateById(membraneChip));
    }


    /**
     * 删除芯片膜
     */
	@DeleteMapping("/{chipIds}")
    public AjaxResult remove(@PathVariable Long[] chipIds) {
        return toAjax(membraneChipService.removeBatchByIds(Arrays.asList(chipIds)));
    }
}
